import PageTools from './PageTools'
import UploadExcel from '../components/UploadExcel'
import moment from 'moment'
import store from '@/store'
export default {
  install(Vue) {
    Vue.component('PageTools', PageTools)
    Vue.component('UploadExcel', UploadExcel)
    // 自定义指令
    Vue.directive('imgerror', {
      inserted(el, binding) {
        // 判断el是否有src
        if (!el.src) {
          el.src = binding.value
        }
        // 判断el的图片是否加载失败,如果加载失败，显示默认的地址
        el.onerror = function() {
          el.src = binding.value
        }
      },
      update(el, binding) {
        // 判断el是否有src
        if (!el.src) {
          el.src = binding.value
        }
        // 判断el的图片是否加载失败,如果加载失败，显示默认的地址
        el.onerror = function() {
          el.src = binding.value
        }
      }
    })
    // 自定义过滤
    Vue.filter('moment', (input) => {
      return moment(input).format('YYYY-MM-DD')
    })

    Vue.prototype.$check = function(point) {
      const res = store.state.user.UserInfo.roles.points
      return res.includes(point)
    }
  }
}
